﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections.Generic;

namespace PivotViewerOffice365.PivotViewerWP
{
    [ToolboxItemAttribute(false)]
    public class PivotViewerWP : WebPart
    {
        protected override void CreateChildControls()
        {
            if (String.IsNullOrEmpty(ListName))
            {
                this.Controls.Add(new LiteralControl("Set propertie for this webpart"));
            
            }
            else
            {
                string strSilverlight = " <object id=\"pivotViewer\" data=\"data:application/x-silverlight-2,\" type=\"application/x-silverlight-2\" width=\"100%\" height=\"90%\">" +
                "<param name=\"source\" value=\"/_catalogs/wp/PivotViewerWP/PivotViewerSL.xap\"/>" +
                string.Format("<param name=\"initParams\" value=\"{0},{1}\" />", "weburl=" + SPContext.Current.Web.Url, "ListName=" + ListName) +
                "<param name=\"onError\" value=\"onSilverlightError\" />" +
                "<param name=\"background\" value=\"white\" />" +
                "<param name=\"minRuntimeVersion\" value=\"5.0.60818.0\" />" +
                "<param name=\"autoUpgrade\" value=\"true\" />" +
                "<a href=\"http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.60818.0\" style=\"text-decoration:none\">" +
                "<img src=\"http://go.microsoft.com/fwlink/?LinkId=161376\" alt=\"Get Microsoft Silverlight\" style=\"border-style:none\"/></a></object>";
                this.Controls.Add(new LiteralControl(strSilverlight));
            }

        }
        public override EditorPartCollection CreateEditorParts()
        {
            List<EditorPart> lstEditorPart = new List<EditorPart>();
            EditorCollectionPivotViewer epv = new EditorCollectionPivotViewer();
            epv.ID = this.ID + "_EditorCollectionPart";
            lstEditorPart.Add(epv);

            EditorUIPivotViewer epui = new EditorUIPivotViewer();
            epui.ID = this.ID + "_EditorUIPart";
            lstEditorPart.Add(epui);

            EditorPartCollection epc = base.CreateEditorParts();
            return new EditorPartCollection(epc, lstEditorPart);
        }

        public string ListName { get; set; }
    }
}
